from typing import List


class Solution:
    def threeSum(self, nums: List[int]) -> List[List[int]]:
        if not nums:
            return []
        def tra(path,start):
            if sum(path)==0 and len(path) == 3:
                new_path = sorted(path)
                if new_path not in result:
                    result.append(new_path)
                return
            for i in range(start,len(nums)):# 可优化
                path.append(nums[i])
                if len(path) >3:
                    break
                tra(path,i+1)
                path.pop()
        result =[]
        path1 = []
        tra(path1,0)
        return result

print(Solution().threeSum([-1,0,1,2,-1,-4]))